﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ART.Common;

namespace ART.Admini.Users
{
    public partial class UserGraduateDetail : System.Web.UI.Page
    {
        protected int UId = 0;
        protected int Id = 0;
        private ART.BLL.B_UserGraduate bll = new ART.BLL.B_UserGraduate();
        private ART.Model.M_UserGraduate model = new ART.Model.M_UserGraduate();
        private BLL.B_dictionary bll_dic = new BLL.B_dictionary();
        private BLL.B_SchoolDic bll_sdic = new BLL.B_SchoolDic();
        private BLL.B_SchoolZY bll_zdic = new BLL.B_SchoolZY();

        protected void Page_Load(object sender, EventArgs e)
        {
            Id = Common.LYRequest.GetInt("id", 0);
            UId = Common.LYRequest.GetInt("UId", 0);
#warning BLL.B_TBAdmin.IsPermissions(0x6c)

            if (!IsPostBack)
            {
                InitData();
            }
        }
        private void InitData()
        {
            JBind.BindList(dropAreaId, bll_dic.GetList("parentid=3").Tables[0], "DictionaryName", "id");
            dropAreaId.Items.Insert(0, new ListItem("请选择", "0"));

            JBind.BindList(dropEduBround, bll_dic.GetList("parentid=10").Tables[0], "DictionaryName", "id");
            dropEduBround.Items.Insert(0, new ListItem("请选择", "0"));

            if (Id > 0)
            {//edit
                model = bll.GetModel(Id);
                if (model != null)
                {
                    txtstartDate.Text = model.startDate.ToString();
                    txtEndDate.Text = model.EndDate.ToString();
                    dropSchoolId.SelectedValue = model.SchoolId.ToString();
                    dropVocationaltid.SelectedValue = model.Vocationaltid.ToString();
                    txtVocationalOther.Text = model.VocationalOther;
                    dropEduBround.SelectedValue = model.EduBround.ToString();
                    txtRemarks.Text = model.Remarks;
                    txtSort.Text = model.Sort.ToString();
                }
            }
        }
        protected void dropAreaId_SelectedIndexChanged(object sender, EventArgs p1)
        {
            if (this.dropAreaId.SelectedValue != "0")
            {
                dropAreaId2.Items.Clear();
                JBind.BindList(dropAreaId2, bll_dic.GetList("parentid=" + this.dropAreaId.SelectedValue).Tables[0], "DictionaryName", "id");
                dropAreaId2.Items.Insert(0, new ListItem("请选择", "0"));
            }
        }

        protected void dropAreaId2_SelectedIndexChanged(object sender, EventArgs p1)
        {
            if (this.dropAreaId2.SelectedValue != "0")
            {
                dropSchoolId.Items.Clear();
                JBind.BindList(dropSchoolId, bll_sdic.GetList("AreaId=" + this.dropAreaId2.SelectedValue).Tables[0], "SchoolName", "id");
                dropSchoolId.Items.Insert(0, new ListItem("请选择", "0"));
            }
        }
        protected void dropSchoolId_SelectedIndexChanged(object sender, EventArgs p1)
        {
            if (this.dropSchoolId.SelectedValue != "0")
            {
                dropVocationaltid.Items.Clear();
                JBind.BindList(dropVocationaltid, JTree.GetTreeTable(bll_zdic.GetList("SchoolId=" + this.dropAreaId2.SelectedValue).Tables[0], "ParentId", "SubobjectName"), "SubobjectName", "id");
                dropVocationaltid.Items.Insert(0, new ListItem("请选择", "0"));
            }
        }
        protected void btnSave_Click(object sender, EventArgs p1)
        {
            if (Id > 0)
            {
                #region __________Edit__________
                model = bll.GetModel(Id);
                model.startDate = DateTime.Parse(txtstartDate.Text);
                model.EndDate = DateTime.Parse(txtEndDate.Text);
                model.SchoolId = int.Parse(dropSchoolId.SelectedValue);
                model.Vocationaltid = int.Parse(dropVocationaltid.SelectedValue);
                model.VocationalOther = txtVocationalOther.Text;
                model.EduBround = int.Parse(dropEduBround.SelectedValue);
                model.Remarks = txtRemarks.Text;
                model.Sort = int.Parse(txtSort.Text);
                if (bll.Update(model))
                {
                    //B_operationLog.CreateOperationLog(B_operationLog.operationLogType.Edit, "", "");
                    MessageBox.JSLoad(sender, "alert('保存成功!');reloadDlg(true);");
                }
                #endregion
            }
            else
            {
                #region __________Add__________
                model.CreateTime = DateTime.Now;
                model.UId =UId;
                model.startDate = DateTime.Parse(txtstartDate.Text);
                model.EndDate = DateTime.Parse(txtEndDate.Text);
                model.SchoolId = int.Parse(dropSchoolId.SelectedValue);
                model.Vocationaltid = int.Parse(dropVocationaltid.SelectedValue);
                model.VocationalOther = txtVocationalOther.Text;
                model.EduBround = int.Parse(dropEduBround.SelectedValue);
                model.Remarks = txtRemarks.Text;
                model.Sort = int.Parse(txtSort.Text);
                if (bll.Add(model) > 0)
                {
                    //B_operationLog.CreateOperationLog(B_operationLog.operationLogType.Add, "", "");
                    MessageBox.JSLoad(sender, "alert('保存成功!');reloadDlg(true);");
                }
                #endregion
            }
        }
    }
}
